package com.samoiloff.ui.btns.check {
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * @author Alexander Slavshik <as.kvint@gmail.com>
	 * created 15.03.2010
	 */
	public class CheckBoxController extends EventDispatcher {
		private var _mc:MovieClip;
		private var _tf:TextField;
		private var _point:MovieClip;
		private var _hitBtn:SimpleButton;
		private var _caption:String;		private var _checked:Boolean;

		public function CheckBoxController(mc:MovieClip, caption:String = 'CheckBox') {
			_mc = mc;
			_tf = _mc.captionTf;
			_point = _mc.pointMc;
			_hitBtn = _mc.hitBtn;
//			Fonts.getInstance().applyDefaultFont(_tf);
			this.caption = caption;
			_point.mouseEnabled = false;
			_point.visible = false;
			_hitBtn.useHandCursor = false;
			_hitBtn.addEventListener(MouseEvent.CLICK, clickHandler); 		}

		protected function clickHandler(event:MouseEvent):void {
			checked = !checked;
			dispatchEvent(event);
		}

		public function get checked():Boolean {
			return _checked;
		}

		public function set checked(checked:Boolean):void {
			_checked = checked;
			_point.visible = _checked;
		}

		public function get caption():String {
			return _caption;
		}

		public function set caption(caption:String):void {
			_tf.text = _caption = caption;
		}
		public function destroy():void{
			_hitBtn.removeEventListener(MouseEvent.CLICK, clickHandler);
			 _tf = null;
			 _point = null;
			 _hitBtn = null;
			_mc = null;
		}

		public function get tf() : TextField {
			return _tf;
		}
	}
}
